package com.example.jt_details;

import com.example.jt_common.vo.ItemParams;
import com.example.jt_manager_pojo.Item;
import com.example.jt_manager_pojo.ItemDesc;
import com.example.jt_manager_service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class GoodsDetailController {

    @Autowired
    ItemService itemService;

    @RequestMapping("/{goods_id}")
    public String getGoodsDetail(@PathVariable(value = "goods_id")Long id, Model model){
        Item item = itemService.queryItemByID(id);
        model.addAttribute("goods",item);

        ItemDesc itemDesc = itemService.queryItemDescById(id);
        model.addAttribute("goods_desc",itemDesc);

        List<ItemParams> params = itemService.queryParamById(id);
        model.addAttribute("goods_params",params);

        return "item";
    }



    @RequestMapping("testjsonparam")
    @ResponseBody
    public Map contextLoads() {
        Item item = itemService.queryItemByID(1474391928);

        ItemDesc itemDesc = itemService.queryItemDescById(1474391928);

        List<ItemParams> params = itemService.queryParamById(1474391928);

        Map map=new HashMap();
        map.put("item",item);
        map.put("desc",itemDesc);
        map.put("params",params);

        return map;
    }
}
